package cn.edu.scau.entity;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="user")
public class User {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="user_id")
	private Integer userId;
	
	@Column(name="account",nullable=false)
	private String account;
	
	@Column(name="password",nullable=false)
	private String password;
	
	@Column(name="nickName",length=32,nullable=false)
	private String nickName;
	
	@Column(name="adress",length=32)
	private String adress;
	
	//用户是否被激活
	@Column(name="status",nullable=false)
	private boolean status=false;
		
	//用户注册时间
	@Column(name="createTime",nullable=true)
	private Date createTime;
	
	/**
	 * 默认是男
	 */
	@Column(name="sex",length=2)
	private String sex="男";
	
	@Column(name="hobby",length=256)
	private String hobby;
	
	@Column(name="job",length=256)
	private String job;
	
	@Column(name="introduction",length=256)
	private String introduction;
	
	/**
	 * 有个默认值，后面加上去
	 */
	@Column(name="head_image",length=256)
	private String headImage;
	
	@JsonIgnore
	@OneToMany(targetEntity=Blog.class,cascade=CascadeType.ALL)
	@JoinTable(name="user_blog"
	,joinColumns=@JoinColumn(name="user_id",referencedColumnName="user_id")
	,inverseJoinColumns=@JoinColumn(name="blog_id",referencedColumnName="blog_id"
	,unique=true))
	private Set<Blog> blogs = new HashSet<Blog>();
	
	@JsonIgnore
	@OneToMany(targetEntity=Blog.class)
	@JoinTable(name="user_collection"
	,joinColumns=@JoinColumn(name="user_id",referencedColumnName="user_id")
	,inverseJoinColumns=@JoinColumn(name="blog_id",referencedColumnName="blog_id"
	,unique=true))
	private Set<Blog> collection = new HashSet<Blog>();
	
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getAdress() {
		return adress;
	}

	public void setAdress(String adress) {
		this.adress = adress;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getHobby() {
		return hobby;
	}

	public void setHobby(String hobby) {
		this.hobby = hobby;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getHeadImage() {
		return headImage;
	}

	public void setHeadImage(String headImage) {
		this.headImage = headImage;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	

	public Set<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(Set<Blog> blogs) {
		this.blogs = blogs;
	}

	public Set<Blog> getCollection() {
		return collection;
	}

	public void setCollection(Set<Blog> collection) {
		this.collection = collection;
	}

	@Transient  
    public Date getLastActivateTime() {  
        Calendar cl = Calendar.getInstance();  
        cl.setTime(createTime);  
        cl.add(Calendar.DATE , 2);
        System.out.println(cl);
        return cl.getTime();  
    }  
}
